﻿/*==============================================================
 * LinkExtensions.cs
 * Copyright (C) 2014 贵州惠众互联 Inc. All rights reserved.
 *==============================================================
 * Author:   罗应红
 * Date:     2014/03/04 17:27:53.
 * Version:  1.0
 * QQ:		 88962800
*==============================================================*/

using System;
using System.Collections.Generic;
using System.Linq;
using QDT.Core.Domain;
using QDT.Web.Admin.Models;

namespace QDT.Web.Admin.Helper {
    public static class LinkExtensions {
        public static IList<LinkModel> ToModelList(this IList<Link> links) {
            return links.Select(ToModel).ToList();
        }

        public static LinkModel ToModel(this Link link) {
            return new LinkModel {
                IsEffect = link.IsEffect,
                Id = link.ID,
                Sort = link.Sort,
                Name = link.Name,
                Description = link.Description,
                Count = link.Count,
                GroupId = link.GroupId,
                GroupName = link.LinkGroup.Name,
                Url = link.Url,
                Img = link.Img,
                ShowIndex = link.ShowIndex
            };
        }
        public static Link ToEntity(this LinkModel model) {
            return new Link {
                IsEffect = model.IsEffect,
                Sort = model.Sort,
                ID = model.Id,
                Name = model.Name,
                Description = model.Description,
                Count = model.Count,
                GroupId = model.GroupId,
                Img = model.Img,
                ShowIndex = model.ShowIndex,
                Url = model.Url
            };
        }
    }
}